//
//  BGProfileViewController.m
//  bigMall
//
//  Created by ios on 16/7/6.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGProfileViewController.h"
#import "BGProfileTableViewCell.h"
#import "BGSetViewController.h"
#import "BGCapitalViewController.h"
#import "BGWMPageViewController.h"
#import "BGXinYuTableViewController.h"
#import "BGAttentionViewController.h"
#import "BGZNXViewController.h"
#import "BGEntrustViewController.h"
#import "BGSellerCenterController.h"
#import "BGBuyerCenterController.h"
#import "BGLoginViewController.h"
#import "BGDateResult.h"
#import "BGLoginMode.h"
#import "BGUserInfoMode.h"
#import "BGRenZhengCenterViewController.h"
#import "BGJiBenMessageViewController.h"
#import "UIImageView+WebCache.h"
#import "BGBasicUrl.h"
#import "UIImage+BGImageExtension.h"
#import "BGUserInfoResult.h"
#import "BGUserInfoMode.h"
#import "BGContactViewController.h"
@interface BGProfileViewController ()<UITableViewDelegate,UITableViewDataSource,UINavigationControllerDelegate> {
    
    UIImage *shadowImage;
    UITableView *_tableView;
    NSArray *_dataArr1;
    NSArray *_dataArr2;
    NSArray *_dataArr3;
    UIImageView *VIEW;//顶部的视图
    UIButton *iconBtn;//头像
    UILabel *iconLab;//头像的名字
    UILabel *balanceLab;//余e
    UILabel *freezeMoneyLab;//冻结的资金
    UILabel *reputationLab;//信誉值
    UIView *xuhuantu;//虚幻图
    UIVisualEffectView *effectview;//毛玻璃
    NSString *check_status;
    
}
@property (nonatomic,copy) NSArray *dataArr;

@end

@implementation BGProfileViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view
    self.navigationController.delegate = self;
    
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor clearColor] size:CGSizeMake(BGWidth, 64)] forBarMetrics:UIBarMetricsDefault];
//    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"设置" style:UIBarButtonItemStylePlain target:self action:@selector(shezhi)];
    
    [item setTintColor:[UIColor whiteColor]];
    
    self.navigationItem.rightBarButtonItem = item;
    
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    //
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.dataArr = @[@"个人信息",@"资产记录",@"我的信誉",@"我的关注",@"我的站内信",@"我的委托"];
    //
    _dataArr1 = [NSArray arrayWithObjects:@"卖家中心",@"买家中心", nil];
    _dataArr2 = [NSArray arrayWithObject:@"企业认证"];
    _dataArr3 = [NSArray arrayWithObject:@"联系我们"];
    //创建基本的视图
    [self createUI];
    
    UIBarButtonItem *backIetm = [[UIBarButtonItem alloc] init];
    backIetm.title =@"";
    self.navigationItem.backBarButtonItem = backIetm;
    
}

- (void)showMessage:(NSString *)message {
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    
    [alertController addAction:okAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
    
}

/**
 *  判断登陆状态
 *
 *  @param controller
 */
- (void)panduan:(UIViewController *)controller {
    
    NSString *state = [[NSUserDefaults standardUserDefaults]objectForKey:State];
    
    if ([state isEqualToString:StateValue] ) {
        
        NSOperationQueue *queue = [[NSOperationQueue alloc] init];
        
        [queue addOperationWithBlock:^{
            
            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                
                self.hidesBottomBarWhenPushed=YES;
                [self.navigationController pushViewController:controller animated:YES];
                self.hidesBottomBarWhenPushed=NO;
                
            }];
            
        }];
        
        
        
    }else {
        
        BGLoginViewController *login = [[BGLoginViewController alloc] init];
        
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:login animated:YES];
        self.hidesBottomBarWhenPushed = NO;
        
    }
    
}

//设置页面的跳转
- (void)shezhi {
    
    NSString *state = [[NSUserDefaults standardUserDefaults]objectForKey:State];
    
    if ([state isEqualToString:StateValue] ) {
        
        
        
        BGSetViewController *set = [[BGSetViewController alloc] init];
        
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:set animated:YES];
        self.hidesBottomBarWhenPushed = NO;
        
        
        
    }else {
        
        BGLoginViewController *login = [[BGLoginViewController alloc] init];
        
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:login animated:YES];
        self.hidesBottomBarWhenPushed = NO;
        
    }
    
}

//懒加载dataArr
-(NSArray *)_dataArr {
    
    if (_dataArr == nil) {
        
        _dataArr = [NSArray array];
        
    }
    
    return _dataArr;
    
}

- (void)createUI {
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, -64, BGWidth, [UIScreen mainScreen].bounds.size.height + 20) style:UITableViewStyleGrouped];
    //    _tableView.contentInset = UIEdgeInsetsMake(200, 0, 0, 0);
    
    _tableView.delegate = self;
    
    _tableView.dataSource = self;
    
    _tableView.showsVerticalScrollIndicator = NO;
    
    //顶部视图的创建
    VIEW = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, BGWidth, BGHight / 2.5)];
    
    VIEW.backgroundColor = [UIColor lightGrayColor];
    VIEW.userInteractionEnabled = YES;
    [VIEW setImage:[UIImage imageNamed:@"亮度-对比度-3"]];
    UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    VIEW.contentMode = UIViewContentModeScaleToFill;
    
    effectview = [[UIVisualEffectView alloc] initWithEffect:blur];
    
    effectview.frame = VIEW.frame;
    
    effectview.alpha = 0.7;
    
    [VIEW addSubview:effectview];
    
    //头像
    iconBtn = [[UIButton alloc] initWithFrame:CGRectMake((BGWidth - VIEW.bottom / 3) / 2, VIEW.bottom / 3.9, VIEW.bottom / 3.2, VIEW.bottom / 3.2)];
    iconBtn.backgroundColor = [UIColor whiteColor];
    iconBtn.clipsToBounds = YES;
    iconBtn.layer.cornerRadius = VIEW.bottom / 6.4;
    [iconBtn setImage:[UIImage imageNamed:@"头像"] forState:UIControlStateNormal];
    [iconBtn addTarget:self action:@selector(iconBtnLogin) forControlEvents:UIControlEventTouchUpInside];
    [VIEW addSubview:iconBtn];
    
    //头像的名字
    iconLab = [[UILabel alloc] initWithFrame:CGRectMake(iconBtn.x, iconBtn.bottom + 10, iconBtn.width, 25)];
    iconLab.textColor = [UIColor whiteColor];
    iconLab.textAlignment = NSTextAlignmentCenter;
    iconLab.font = [UIFont systemFontOfSize:14];
    [VIEW addSubview:iconLab];
    
    //虚幻图
    xuhuantu = [[UIView alloc] initWithFrame:CGRectMake(0, VIEW.bottom - 66, BGWidth, 66)];
    xuhuantu.backgroundColor = [UIColor blackColor];
    xuhuantu.alpha = 0.1;
    xuhuantu.hidden = YES;
    [VIEW addSubview:xuhuantu];
    
    //余e
    balanceLab = [[UILabel alloc] initWithFrame:CGRectMake(((BGWidth - 2)/3 - (BGWidth - 2)/3/ 1.8) / 2, VIEW.bottom - 55, (BGWidth - 2)/3 / 1.8, 15)];
    balanceLab.textColor = [UIColor whiteColor];
    balanceLab.textAlignment = NSTextAlignmentCenter;
    balanceLab.font = [UIFont systemFontOfSize:12];
    [VIEW addSubview:balanceLab];
    
    UILabel *lab1 = [[UILabel alloc] initWithFrame:CGRectMake(balanceLab.x,balanceLab.bottom + 10, balanceLab.width, balanceLab.height)];
    lab1.textColor = [UIColor whiteColor];
    lab1.text = @"账户余额";
    lab1.font = [UIFont systemFontOfSize:14];
    lab1.textAlignment = NSTextAlignmentCenter;
    [VIEW addSubview:lab1];
    
    //冻结的资金
    freezeMoneyLab = [[UILabel alloc] initWithFrame:CGRectMake(balanceLab.right + 1 + 2 * balanceLab.x, balanceLab.y, balanceLab.width, balanceLab.height)];
    freezeMoneyLab.textColor = [UIColor whiteColor];
    freezeMoneyLab.textAlignment = NSTextAlignmentCenter;
    freezeMoneyLab.font = [UIFont systemFontOfSize:12];
    [VIEW addSubview:freezeMoneyLab];
    
    UILabel *lab2 = [[UILabel alloc] initWithFrame:CGRectMake(freezeMoneyLab.x, freezeMoneyLab.bottom + 10, freezeMoneyLab.width, freezeMoneyLab.height)];
    lab2.textColor = [UIColor whiteColor];
    lab2.text = @"冻结资金";
    lab2.font = [UIFont systemFontOfSize:14];
    lab2.textAlignment = NSTextAlignmentCenter;
    [VIEW addSubview:lab2];
    
    //信誉值
    reputationLab = [[UILabel alloc] initWithFrame:CGRectMake(freezeMoneyLab.right + 2 + 2 * balanceLab.x, balanceLab.y, balanceLab.width, balanceLab.height)];
    reputationLab.textColor = [UIColor whiteColor];
    reputationLab.textAlignment = NSTextAlignmentCenter;
    reputationLab.font = [UIFont systemFontOfSize:12];
    [VIEW addSubview:reputationLab];
    
    UILabel *lab3 = [[UILabel alloc] initWithFrame:CGRectMake(reputationLab.x, reputationLab.bottom + 10, reputationLab.width, reputationLab.height)];
    lab3.textColor = [UIColor whiteColor];
    lab3.text = @"信誉值";
    lab3.font = [UIFont systemFontOfSize:14];
    lab3.textAlignment = NSTextAlignmentCenter;
    [VIEW addSubview:lab3];
    
    //创建分割线
    for (int i = 1; i <= 2; i++) {
        
        UIView *v = [[UIView alloc] initWithFrame:CGRectMake(i * (BGWidth - 2)/3, balanceLab.y, 1, balanceLab.height + 10 +lab1.height)];
        v.backgroundColor = [UIColor whiteColor];
        [VIEW addSubview:v];
        
    }
    
    _tableView.tableHeaderView = VIEW;
    [self.view addSubview:_tableView];
    
}

//头像下标题判断
- (void)pda {
    
    NSString *state = [[NSUserDefaults standardUserDefaults]objectForKey:State];
    
    if ([state isEqualToString:StateValue] ) {
        [self loadInter1];
        if ([[NSUserDefaults standardUserDefaults] objectForKey:@"icon"] != nil || [[[NSUserDefaults standardUserDefaults] objectForKey:@"iconName"] isEqualToString:_imgsrc])
        {
            VIEW.image = [UIImage imageWithData:[[NSUserDefaults standardUserDefaults] objectForKey:@"icon"]];
            [iconBtn setImage:[UIImage imageWithData:[[NSUserDefaults standardUserDefaults] objectForKey:@"icon"]] forState:UIControlStateNormal];
//            iconLab.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"iconName"];
        } else {
        
        [self loadInter1];
        }
        [self loadInter1];
        effectview.hidden = NO;
        xuhuantu.hidden = NO;
        
//        balanceLab.text = @"10000";
//        freezeMoneyLab.text = @"99999";
//        reputationLab.text = @"100";
        
//        [iconBtn setImage:self.iconImage forState:UIControlStateNormal];
        
    }else {
        
        effectview.hidden = YES;
        [iconBtn setImage:[UIImage imageNamed:@"头像"] forState:UIControlStateNormal];
        [VIEW setImage:[UIImage imageNamed:@"亮度-对比度-3"]];
        iconLab.text = @"马上登陆";
        balanceLab.text = @"0.00";
        freezeMoneyLab.text = @"0.00";
        reputationLab.text = @"0";
        
    }
    
    
    
}

- (void)loadInter1 {
    
    [BGDateResult getUserInfoSuccess:^(NSString *status, NSString *msg, NSDictionary *res) {

        if ([status intValue] == 1) {
            
//            BGUserInfoMode *model = (BGUserInfoMode *)res;
            
            iconLab.text = res[@"name"];
            
            check_status = res[@"check_status"];
            
            balanceLab.text = res[@"cash"];
            freezeMoneyLab.text = res[@"frozen"];
            reputationLab.text = res[@"credit"];
            
            _imgsrc = res[@"imgsrc"];
//            [[NSUserDefaults standardUserDefaults] setObject:model.name forKey:@"iconName"];
//            [[NSUserDefaults standardUserDefaults] synchronize];
            NSLog(@"%@",[NSString stringWithFormat:@"%@%@",[BGBasicUrl getBasicUrl],res[@"imgsrc"]]);
            NSData *dataImage = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",[BGBasicUrl getBasicUrl],res[@"imgsrc"]]]];
            
            UIImage *image = [UIImage imageWithData:dataImage];
            
//            VIEW.contentMode = UIViewContentModeScaleToFill;
//            VIEW.image = [image imageByScalingToSize:CGSizeMake(BGWidth, BGHight / 2.3)];
            NSLog(@"model.imgsrc === %@",res[@"imgsrc"]);
            NSLog(@"a === %@",[[NSUserDefaults standardUserDefaults] objectForKey:@"iconName"]);
            if (![[[NSUserDefaults standardUserDefaults] objectForKey:@"iconName"] isEqualToString:res[@"imgsrc"]]) {
                
//                [VIEW sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[BGBasicUrl getBasicUrl],model.imgsrc]]];
                VIEW.image = image;
                [iconBtn setImage:image forState:UIControlStateNormal];
                
                [[NSUserDefaults standardUserDefaults] setObject:UIImagePNGRepresentation(image) forKey:@"icon"];
                [[NSUserDefaults standardUserDefaults] setObject:res[@"imgsrc"] forKey:@"iconName"];
                [[NSUserDefaults standardUserDefaults] synchronize];
                
            }
            
            
        }else if ([status intValue] == -2) {
            
            
            [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:State];
            [[NSUserDefaults standardUserDefaults] synchronize];
            [self pda];
            
        }
        
    } failure:^(NSError *error) {
        
    }];    
    
}

- (void)iconBtnLogin {
    
    NSString *state = [[NSUserDefaults standardUserDefaults]objectForKey:State];
    
    if ([state isEqualToString:StateValue] ) {
        
        BGJiBenMessageViewController *a= [[BGJiBenMessageViewController alloc] init];
        
        [self panduan:a];
        
    }else {
        
        BGLoginViewController *login = [[BGLoginViewController alloc] init];
         
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:login animated:YES];
        self.hidesBottomBarWhenPushed = NO;
        
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 4;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section == 0) {
        
        return _dataArr.count;
        
    }else if (section == 1) {
        
        return 2;
        
    }else {
        
        return 1;
        
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 50;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section == 0) {
        
        if (indexPath.row == 1) {
            
            BGCapitalViewController *capital = [[BGCapitalViewController alloc] init];
            [self panduan:capital];
            
        }else if (indexPath.row == 0) {
            
            BGJiBenMessageViewController *a= [[BGJiBenMessageViewController alloc] init];
            
            [self panduan:a];
            
        } else if (indexPath.row == 2) {
            
            BGXinYuTableViewController *xinyu = [[BGXinYuTableViewController alloc] init];
            
            [self panduan:xinyu];
            
        } else if (indexPath.row == 3) {
            
            BGAttentionViewController *a =[[BGAttentionViewController alloc] init];
            
            [self panduan:a];
            
        } else if (indexPath.row == 4) {
            
            BGZNXViewController *a =[[BGZNXViewController alloc] init];
            
            [self panduan:a];
            
        } else {
            
            BGEntrustViewController *a = [[BGEntrustViewController alloc] init];
            a.controllerType = @"profile";
            [self panduan:a];
            
        }
        
    }else if (indexPath.section == 1) {
        
        if (indexPath.row == 0) {
            
            BGSellerCenterController *a = [[BGSellerCenterController alloc] init];
            
            
            NSString *state = [[NSUserDefaults standardUserDefaults]objectForKey:State];
            
            if ([state isEqualToString:StateValue] ) {
                
                NSOperationQueue *queue = [[NSOperationQueue alloc] init];
                
                [queue addOperationWithBlock:^{
                    
                    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                        
                        if ([check_status intValue] == 2)
                        {
                        self.hidesBottomBarWhenPushed=YES;
                        [self.navigationController pushViewController:a animated:YES];
                            self.hidesBottomBarWhenPushed=NO;
                        }else
                        {
                            [self showMessage:@"需要先企业认证!"];
                        }
                    }];
                    
                }];
                
            }
            else {
                
                BGLoginViewController *login = [[BGLoginViewController alloc] init];
                
                self.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:login animated:YES];
                self.hidesBottomBarWhenPushed = NO;
                
            }
            
        } else {
            
            BGBuyerCenterController *a = [[BGBuyerCenterController alloc] init];
            
            [self panduan:a];
            
        }
        
    } else if (indexPath.section == 2) {
        
        BGRenZhengCenterViewController *a = [[BGRenZhengCenterViewController alloc] init];
        
        a.check_status = check_status;
        
        [self panduan:a];
    } else {
        BGContactViewController *a = [[BGContactViewController alloc] init];
        self.hidesBottomBarWhenPushed=YES;
        [self.navigationController pushViewController:a animated:YES];
        self.hidesBottomBarWhenPushed=NO;
//        [self callPhone];
        
    }
    
}

- (void)callPhone {
    
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *callAction = [UIAlertAction actionWithTitle:@"拨打" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[[NSMutableString alloc] initWithFormat:@"telprompt://%@",@"10086"]]];
        
    }];
    [alertVC addAction:callAction];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertVC addAction:cancelAction];
    
    [self presentViewController:alertVC animated:YES completion:^{
        
    }];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView registerNib:[UINib nibWithNibName:@"BGProfileTableViewCell" bundle:nil]     forCellReuseIdentifier:@"celId"];
    
    BGProfileTableViewCell *cel = [tableView dequeueReusableCellWithIdentifier:@"celId" forIndexPath:indexPath];
    
    cel.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    
    if (indexPath.section == 0) {
        
        if (indexPath.row == 0) {
            cel.imageIcon.image = [UIImage imageNamed:@"1"];
        }else if (indexPath.row == 1){
            
            cel.imageIcon.image = [UIImage imageNamed:@"资产记录"];
            
        }else if (indexPath.row == 2){
            
            cel.imageIcon.image = [UIImage imageNamed:@"我的信誉"];
            
        }else if (indexPath.row == 3){
            
            cel.imageIcon.image = [UIImage imageNamed:@"我的关注"];
            
        }else if (indexPath.row == 4){
            
            cel.imageIcon.image = [UIImage imageNamed:@"我的站内信"];
            
        }else {
            
            cel.imageIcon.image = [UIImage imageNamed:@"我的委托"];
            
        }

        
        
//        cel.imageIcon.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld",(long)indexPath.row + 1]];
        cel.lab.text = self.dataArr[indexPath.row];
        
    }
    else if (indexPath.section == 1) {
        
//        cel.imageIcon.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld%ld",(long)indexPath.row + 1,(long)indexPath.row + 1]];
        cel.lab.text = _dataArr1[indexPath.row];
        if (indexPath.row == 0) {
            cel.imageIcon.image = [UIImage imageNamed:@"卖家中心"];
        }else {
            
            cel.imageIcon.image = [UIImage imageNamed:@"买家中心、"];
            
        }
        
    }
    else if (indexPath.section == 2) {
        
        cel.imageIcon.image = [UIImage imageNamed:@"企业认证"];
        cel.lab.text = _dataArr2[indexPath.row];
        
    } else {
        
        cel.imageIcon.image = [UIImage imageNamed:@"icon_Contact us"];
        cel.lab.text = _dataArr3[indexPath.row];
        
    }
    
    return cel;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    if (section == 0) {
        
        return 16;
        
    }else {
        
        return 16;
        
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;//设置尾视图高度为0.01
}
- (void)viewWillAppear:(BOOL)animated {
    
//    [super viewWillAppear:animated];
//    
//    [_tableView setContentOffset:CGPointMake(0, 0) animated:YES];
//
    self.tabBarController.tabBar.hidden = NO;
//
    [self pda];
//    shadowImage = self.navigationController.navigationBar.shadowImage;
//    
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
//    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
        [super viewWillAppear:animated];
    
        [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    
        [self.navigationController.navigationBar setShadowImage:[UIImage new]];
   
}
- (void)viewWillDisappear:(BOOL)animated {
//    
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"a"] forBarMetrics:UIBarMetricsDefault];
//    
//    self.navigationController.navigationBar.shadowImage = shadowImage;
    [super viewWillDisappear:animated];
    
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];

    [self.navigationController.navigationBar setShadowImage:nil];
}

@end
